<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<h1>个人中心</h1>
<span class="show">xiaohua</span>

<script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.js"></script>
<script>

// 获取token
let token = localStorage.getItem('token');
if (token) {
    // 发送请求，验证token
    axios({
        method: 'get',
        headers: {
            'authorization': token
        },
        url: 'http://localhost:9090/users/islogin'
    })
    .then((response)=>{
        let {data} = response;
        // 判断是否已登录
        if (data.code === 1) {
            // 已登录，显示登录账号
            document.querySelector('.show').innerText = data.info.username;
        }
        else{
            // 未登录，跳转到登录页
            location.href = './login.html'
        }
    })
}
else{
    // 未登录，跳转到登录页
    location.href = './login.html'
}

</script>
</body>
</html>